﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using GalaSoft.MvvmLight;
using System.Collections.ObjectModel;

namespace CochonMVVM.Articles
{

    public class ArticlesViewModel : ViewModelBase
    {
        //private readonly IDataService _dataService;
        private static CochonMCDDataContext dataContext = new CochonMCDDataContext();

        #region Properties

        private ObservableCollection<Article> articleCollection = new ObservableCollection<Article>();

        public ObservableCollection<Article> ArticleCollection
        {
            get { return articleCollection; }
            set {
                if (articleCollection != value)
                {
                    articleCollection = value;
                    RaisePropertyChanged(() => ArticleCollection);
                }
            }
        }

        #endregion

        #region InitializeData

        /// <summary>
        /// Récupération des articles existants en BDD
        /// </summary>
        private void InitializeData()
        {
            foreach (Article currentArticle in dataContext.Article)
            {
                ArticleCollection.Add(currentArticle);
            }
        }

        #endregion

        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public ArticlesViewModel()
        {
            //_dataService = dataService;
            //_dataService.GetData(
            //    (item, error) =>
            //    {
            //        if (error != null)
            //        {
            //            // Report error here
            //            return;
            //        }

            //        WelcomeTitle = item.Title;
            //    });

            InitializeData();
        }
    }
}
